<?php

namespace App\Daos\Admin\Users;

use App\Models\Users\Group;
use App\Models\Users\Users;

class GroupDao
{
    /**
     * Notes: 冲突测试1
     * User: 戎飞
     * Date: 2023/7/31
     * Time: 10:26
     * @param $size
     * @param $offset
     * @return array
     */
    public static function groupList ($size,$offset){
        $data['total'] = Group::get()->count();
        $data['data'] = Group::offset($offset)->limit($size)->get();
        return $data;
    }

    public static function groupAdd ($name){
        $res = Group::create([
            'name' => $name,
            'created_at' => date('Y-m-d H:i:s')
        ]);
        return $res;
    }

    public static function groupUpdate ($data){
        $res = Group::where('id',$data['id'])->update([
            'name' => $data['name'],
            'updated_at' => date('Y-m-d H:i:s')
        ]);
        return $res;
    }

    public static function groupDelete ($id){
        $res = Group::find($id);
        $res->delete();
        return $res;
    }

    public static function sendGroup ($user,$group){
        return Users::whereIn('id',$user)->update([
            'group' => $group,
            'updated_at' => date('Y-m-d H:i:s')
        ]);
    }
}
